# src/schemas/sys_objects_field_rule.py
from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime


# ---------------- 基础字段 ----------------
class SysObjectsFieldRuleBase(BaseModel):
    field_id: str = Field(..., max_length=36, description="对应 sys_objects_field.id")
    rule_type: str = Field(..., max_length=30, description="规则类型：validation / placeholder / tooltip / disableWhen")
    rule_key: str = Field(..., max_length=50, description="规则名：required、regex、min、max、disableWhen 等")
    rule_value: str = Field(..., max_length=200, description="规则值：true、10、^[0-9]+$、form.type==='a' 等")
    priority: int = Field(0, ge=0, description="同字段内执行顺序，越小越先")
    enabled: bool = Field(True, description="是否启用本条规则")
    deletion_mark: bool = Field(False, description="删除标志")
    deletion_reason: Optional[str] = Field(None, max_length=255)
    deletion_date: Optional[datetime] = None
    deletion_by: Optional[str] = Field(None, max_length=255)
    create_date: Optional[datetime] = None
    creator_by: Optional[str] = Field(None, max_length=255)
    last_updated_date: Optional[datetime] = None
    last_updated_by: Optional[str] = Field(None, max_length=255)


# ---------------- 创建/更新 ----------------
class SysObjectsFieldRuleCreate(SysObjectsFieldRuleBase):
    api_id: Optional[str] = Field(None, max_length=36, description="API主键，用于关联其他系统")


# ---------------- 响应 ----------------
class SysObjectsFieldRule(SysObjectsFieldRuleBase):
    id: str
    api_id: Optional[str] = Field(None, max_length=36, description="API主键，用于关联其他系统")

    class Config:
        from_attributes = True  # ORM 兼容
